package statistics;

import java.util.Random;


public class BernoulliDistribution extends Distribution{

    protected double p;
    
    public BernoulliDistribution( double p , Random random ){
        this.p = p;
        this.random = random;
    }
            

    public double expectation() {
       return p;
    }


    public double variance() {
        return p*(1-p);
    }


    public double nextRandom() {
        double U = random.nextDouble();
        int result;
        if(U<=p)
            result = 1;
        else
            result = 0;
        return result;
    }
    
    
}